﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region Module Attributes
	#FullScreen: False
	#IncludeTitle: True
#End Region

'Activity module
Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Dim edtServerIP As EditText
	Dim edtServerPort As EditText
	Dim btnConn As Button
	Dim btnSave As Button
	
	Dim sSql As String
	Dim bConnOk As Boolean
	
	Dim HttpClientTool As HttpClient
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormLoginConfig")
	Activity.Title = "选项"
	
	HttpClientTool.Initialize("HttpClientTool")
	
	InitData
	
	InitLayOut
	
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitData

	bConnOk = False
	edtServerIP.Text = PublicVar.GV_ServerIP
	edtServerPort.Text = PublicVar.GV_ServerPort
End Sub

Sub InitLayOut
	If edtServerIP.Text = "" Then
		edtServerIP.RequestFocus
	Else If edtServerPort.Text = "" Then
		edtServerPort.RequestFocus
		
	End If
End Sub

Sub btnSave_Click
	If edtServerIP.Text.Trim = "" Then
		ToastMessageShow("请输入服务器IP!",False)
		edtServerIP.RequestFocus
		Return		
	End If
	
	If edtServerPort.Text.Trim = "" Then
		ToastMessageShow("请输入服务器端口!",False)
		edtServerPort.RequestFocus
		Return		
	End If
	
	PublicVar.GV_ServerIP = edtServerIP.Text.Trim
	PublicVar.GV_ServerPort = edtServerPort.Text.Trim
	
	sSql = "UPDATE ZD_CONFIG SET SERVERIP='"&PublicVar.GV_ServerIP&"',SERVERPORT="&PublicVar.GV_ServerPort
	Log("SQL: " & sSql)
	Try
		PublicVar.GV_SQLTool.ExecNonQuery(sSql)
	Catch
		ToastMessageShow("设置失败!",False)
		Log(LastException.Message)
		Return
	End Try
	ToastMessageShow("设置成功!",False)
End Sub
Sub btnConn_Click
	Dim sURL As String
	Dim hrRequest As HttpRequest 
	
	sURL = PublicVar.GetServerUrl  
	hrRequest.InitializeGet(sURL)
	hrRequest.Timeout = PublicVar.GV_ConnTimeOut   
	If HttpClientTool.Execute(hrRequest, 1) = False Then  Return 
	ProgressDialogShow("正在连接服务器，请稍候...")	
	
End Sub

Sub HttpClientTool_ResponseSuccess (Response As HttpResponse, TaskId As Int)    
  ProgressDialogHide       
  bConnOk = True
  ToastMessageShow ("连接服务器成功", True)	
End Sub
Sub HttpClientTool_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)   
  ProgressDialogHide
	Dim sMsg As String
  Log(Reason)    
  Log(StatusCode) 
	bConnOk = False
  sMsg = "连接服务器失败."    
  If Reason <> Null Then sMsg = sMsg & CRLF & Reason    
  ToastMessageShow (sMsg, True)	
End Sub